package com.sphd.restaurantsystem.presenter;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.CouponInfo;
import com.sphd.restaurantsystem.model.SureOrderModelImpl;
import com.sphd.restaurantsystem.view.SureOrderView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;

/**
* Created by Hu on 2016/12/05
*/

public class SureOrderPresenterImpl implements SureOrderPresenter {
    SureOrderModelImpl sureOrderModel;
    SureOrderView sureOrderView;

    public SureOrderPresenterImpl(SureOrderView sureOrderView) {
        this.sureOrderView = sureOrderView;
        sureOrderModel=new SureOrderModelImpl();
    }

    @Override
    public void addData(String url) {
        sureOrderView.showLoading();
        sureOrderModel.sendUrl(url,this);
    }

    @Override
    public void sendError(VolleyError error) {

    }

    @Override
    public void sendCards(List<CouponInfo> cardInfos) {
        sureOrderView.recCards(cardInfos);
    }


    @Override
    public void sendMoney(double account,String time) {
        sureOrderView.recMoney(account,time);
        sureOrderView.dissLoading();
    }

    @Override
    public void sendMap(Map<String, String> map) {
        sureOrderView.showLoading();
        sureOrderModel.sendMap(map,this);
    }

    @Override
    public void sendOrderRes(String response) {

        try {
            if (new JSONObject(response).getInt("res")==1){
                sureOrderView.recOk();
            }else {
                sureOrderView.recFaile();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        sureOrderView.dissLoading();
    }
}